"use strict";
cc._RF.push(module, '19e64eCR8JPnLwuwQn0STQe', 'BounceMoveTween');
// eazax-ccc/components/tweens/BounceMoveTween.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 弹性移动效果
 * @see BounceMoveTween.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/tweens/BounceMoveTween.ts
 */
var BounceMoveTween = /** @class */ (function (_super) {
    __extends(BounceMoveTween, _super);
    function BounceMoveTween() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.frequency = 4;
        _this.decay = 2;
        _this.tween = null;
        return _this;
    }
    BounceMoveTween.prototype.start = function () {
        this.play(cc.v2(0, 0), 0.5);
    };
    /**
     * 播放
     * @param targetPos 目标位置
     * @param time 移动时间
     */
    BounceMoveTween.prototype.play = function (targetPos, time) {
        var _this = this;
        this.stop();
        // 当前位置
        var curPos = this.node.getPosition();
        // 方向
        var direction = targetPos.sub(curPos).normalize();
        // 时长
        var bouncingTime = 0.75; // 弹跳时长
        // 振幅
        var amplitude = cc.Vec2.distance(curPos, targetPos) / time;
        // 播放
        this.tween = cc.tween(this.node);
        cc.tween(this.node)
            .to(time, { x: targetPos.x, y: targetPos.y }, { easing: 'quadIn' })
            .to(bouncingTime, {
            position: {
                value: cc.v3(targetPos.x, targetPos.y),
                progress: function (start, end, current, t) {
                    var pos = direction.mul(-_this.getDifference(amplitude, t));
                    return cc.v3(pos.x, pos.y);
                }
            }
        })
            .start();
    };
    /**
     * 停止
     */
    BounceMoveTween.prototype.stop = function () {
        this.tween && this.tween.stop();
    };
    /**
     * 获取目标时刻弹性幅度
     * @param amplitude 幅度
     * @param time 时间
     */
    BounceMoveTween.prototype.getDifference = function (amplitude, time) {
        // 角速度（ω=2nπ）
        var angularVelocity = this.frequency * Math.PI * 2;
        return amplitude * (Math.sin(time * angularVelocity) / Math.exp(this.decay * time) / angularVelocity);
    };
    __decorate([
        property({ tooltip: CC_DEV && '频率（弹跳次数）' })
    ], BounceMoveTween.prototype, "frequency", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '衰退指数' })
    ], BounceMoveTween.prototype, "decay", void 0);
    BounceMoveTween = __decorate([
        ccclass
    ], BounceMoveTween);
    return BounceMoveTween;
}(cc.Component));
exports.default = BounceMoveTween;

cc._RF.pop();